package com.yonyou.iuap.controller.app;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yonyou.iuap.pub.JsonUtils;
import com.yonyou.iuap.shell.entity.exp.CompatiblePojo;
import com.yonyou.iuap.shell.entity.exp.CompatiblePubPojo;
import com.yonyou.iuap.shell.pub.ResultDto;
import com.yonyou.iuap.shell.service.intf.ICompatiblerelationService;

/**
 * 壳牌和竞品关系
 * **/
@Controller
@RequestMapping(value = "compatiblerealtion")
public class CompatiblerealtionEntityController {
	private final Logger logger = (Logger) LoggerFactory.getLogger(getClass());
	private long start, end;
	@Autowired
	private ICompatiblerelationService compatiblerealtionServiceImpl;

	@RequestMapping(value = "App/selectcompatiblerealtion", method = RequestMethod.POST)
	@ResponseBody
	public String selectcompatiblerealtion(HttpServletRequest resq,
			@RequestBody HashMap parMap) {
		start = System.currentTimeMillis();
		ResultDto rsDto = new ResultDto();
		String pk_industry_chart = parMap.get("pk_industry_chart").toString();
		if (StringUtils.isEmpty(pk_industry_chart)) {
			rsDto.setStatus(1);
			rsDto.setMessage("查询条件不能为空!");
		} else {
			List<CompatiblePojo> listvo = compatiblerealtionServiceImpl
					.querycompatible(pk_industry_chart);
			List<CompatiblePubPojo> list2 = compatiblerealtionServiceImpl
					.querycompatiblepublic(pk_industry_chart);
			Map map = new HashMap();
			map.put("compatible", listvo);
			map.put("product", list2);
			rsDto.setStatus(0);
			rsDto.setMessage("数据查询成功!");
			rsDto.setNum(listvo == null ? 0 : listvo.size() + list2.size());
			rsDto.setCount(listvo == null ? 0 : listvo.size() + list2.size());
			rsDto.setData(map);
		}

		String rtn_json = JsonUtils.toJsonStr(rsDto);
		end = System.currentTimeMillis();
		logger.info("selectcompatiblerealtion接口调用时间"
				+ String.valueOf(end - start));
		return rtn_json;
	}

}
